package org.micro.test.service.impl;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.micro.test.entity.UseCase;
import org.micro.test.mapper.UseCaseMapper;
import org.micro.test.service.IUseCaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UseCaseServiceImpl extends ServiceImpl<UseCaseMapper,UseCase> implements IUseCaseService {
    @Autowired
    private UseCaseMapper useCaseMapper;
    @Override
    public UseCase getUserById(Integer userId) {
        return useCaseMapper.selectById(userId);
    }

    /**
     * 分页查询
     */
    public Page selectByPage(Page page) {
        List<UseCase> useCaseList = useCaseMapper.selectByPage(page);
        page.setRecords(useCaseList);
        return page;
    }

    @Override
    public boolean updateUseCase(UseCase userCase) {
        return userCase.updateById();
    }

    @Override
    public boolean addUseCase(UseCase useCase) {
        return useCase.insert();
    }
    //TODO 批量增加
    @Override
    public boolean addMultiUseCase(List<UseCase> useCaseList) {
        return false;
    }

    @Override
    public boolean deleteUseCaseById(Integer useId) {
        return useCaseMapper.deleteById(useId) == 1 ? true : false;
    }

    @Override
    public List<UseCase> searchUseCaseByName(String useCaseName) {
        return useCaseMapper.selectList(new EntityWrapper<UseCase>().eq("title",useCaseName));
    }
}
